package com.fjrz.myapplication

import android.content.Intent
import android.widget.TextView
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.module.lemlin.owner.OwnerViewModeActivity
import com.module.lemlin.owner.OwnerViewModel
import com.zhihu.matisse.Matisse
import com.zhihu.matisse.MimeType
import com.zhihu.matisse.engine.impl.GlideEngine
import java.io.File

class MainActivity : OwnerViewModeActivity<BaseViewModel>() {

    override fun viewModel(): BaseViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_main

    override fun initView() {

        findViewById<TextView>(R.id.textTest).setOnClickListener {

            Matisse.from((this))
                .choose(MimeType.ofImage())
                .countable((true))
                .maxSelectable((1))
                .imageEngine(GlideEngine())
                .forResult((100))
            //viewModel.test1()
        }

    }

    override fun initData() {
//        LogUtils.e("=====${viewModel.user.value}")
    }

    override fun initViewMode() {
//        viewModel.user.observe(this, Observer {
//            LogUtils.e("================fasdfad   ${it}")
//        })

        viewModel.userSmsLiveData.observe(this, Observer {
            LogUtils.e("======${GsonUtils.toJson(it)}")
            toast(GsonUtils.toJson(it))
        })
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 100 && resultCode == RESULT_OK) {
            val pathList: MutableList<String> = Matisse.obtainPathResult(data).toMutableList()
            if (pathList.size == 0)
                return
            viewModel.upload("/api/common/upload", pathList[0])
        }
    }
}